package kr.or.common.security.ibatis;

import java.util.*;

import kr.or.common.security.ibatis.domain.*;
import kr.or.javacafe.member.domain.*;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.GrantedAuthority;


@SuppressWarnings("serial")
public class IbatisUserDetail implements UserDetails {

	private User user;
	private List<GrantedAuthority> authorities;
	
	

	public IbatisUserDetail(User user, List<GrantedAuthority> authorities) {
		this.user = user;
		this.authorities = authorities;
	}

	@Override
	public Collection<GrantedAuthority> getAuthorities() {
		return authorities;
	}

	@Override
	public String getPassword() {
		return user.getPassword();
	}

	@Override
	public String getUsername() {
		return user.getId();
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		if (user.getEnabled().equals("Y"))
			return true;
		else
			return false;
	}
	
	public User getUser() {
		return user;
	}
}
